package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.OutCheckEntity
import com.c.ctgproject.ui.collect.check.OutCheckDetailActivity
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler
import org.jetbrains.anko.startActivity

class CheckOutListAdapter(private val context: Context, private val mList: ArrayList<OutCheckEntity.DataBean.ListBean>) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_check_out_list_, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mNo.text = data.bizNo.handlerNull()
            val dismantleType = when (data.outMethod) {
                1 -> "电池"
                2 -> "零件"
                3 -> "物料"
                else -> "暂无数据"
            }
            holder.dismantleType.text = dismantleType

            val outType = when (data.outType) {
                1 -> "销售出库"
                2 -> "借用出库"
                3 -> "其他出库"
                else -> "暂无数据"
            }
            holder.outType.text = outType



            holder.mTimeTV.text = data.createTime.noDataHandler()
            holder.mUserNameTV.text = data.createPersonName.noDataHandler()

            if (data.status == 1) {
                holder.mBottomRL.visibility = View.VISIBLE
            } else {
                holder.mBottomRL.visibility = View.GONE
            }


            holder.mBottomRL.setOnClickListener {
                holder.mBTN.performClick()
            }
            //审批
            holder.mBTN.setOnClickListener {
                context.startActivity<OutCheckDetailActivity>(
                    MyConstants.POSITION to position,
                    MyConstants.ID to data.outOrderId)
            }
            //详情
            holder.mParentLL.setOnClickListener {
                val show = data.status != 1
                context.startActivity<OutCheckDetailActivity>(
                    MyConstants.ID to data.outOrderId,
                    MyConstants.JUST_SHOW to show
                )
            }
            holder.mStatueTV.visibility = if (data.isReject == 1) View.VISIBLE else View.GONE
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mNo: TextView = view.findViewById(R.id.mNo)
        val dismantleType: TextView = view.findViewById(R.id.dismantleType)
        val mStatueTV: TextView = view.findViewById(R.id.mStatueTV)
        val outType: TextView = view.findViewById(R.id.outType)
        val mTimeTV: TextView = view.findViewById(R.id.mTimeTV)
        val mUserNameTV: TextView = view.findViewById(R.id.mUserNameTV)
        val mBottomRL: RelativeLayout = view.findViewById(R.id.mBottomRL)
        val mBTN: Button = view.findViewById(R.id.mBTN)
        val mParentLL: LinearLayoutCompat = view.findViewById(R.id.mParentLL)
    }
}